package onlinejudge.controller;

import onlinejudge.service.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/admin")
public class AdminController {

	@Resource
	private UserService userService;
	@Resource
	private NoticeService noticeService;
	@Resource
	private ProblemService problemService;
	@Resource
	private CommunityService communityService;
	@Resource
	private SolutionService solutionService;
	
	@RequestMapping("/index")
	public String index() {
		return "admin/index";
	}
	
	@RequestMapping("/myDesktop")
	public String myDesktop(HttpServletRequest request) {
		Map<String, Object> parameters=new HashMap<String, Object>();
		request.setAttribute("userCount", userService.getUserCount());
		request.setAttribute("noticeCount", noticeService.getNoticeCount());
		request.setAttribute("noticeList", noticeService.queryAllNotice(parameters));
		request.setAttribute("problemCount", problemService.getProblemCount());
		request.setAttribute("itemCount", communityService.getCommunityCount());
		request.setAttribute("solutionCount", solutionService.querySolution(parameters).size());
		return "admin/myDesktop";
	}
	
	@RequestMapping("/userList")
	public String userList(HttpServletRequest request) {
		return "admin/userList";
	}
	
	@RequestMapping("/updatePwd")
	public String updatePwd(boolean updateFlag,HttpServletRequest request) {
		request.setAttribute("updateFlag", updateFlag);
		return "admin/updatePwd";
	}
	
	@RequestMapping("/noticeList")
	public String noticeList(boolean addFlag,HttpServletRequest request) {
		request.setAttribute("addFlag", addFlag);
		return "admin/noticeList";
	}
	
	@RequestMapping("/addProblem")
	public String addProblem(boolean addFlag,HttpServletRequest request) {
		Map<String, Object> parameters=new HashMap<String, Object>();
		request.setAttribute("problemTypeList", problemService.queryAllProblemType(parameters));
		request.setAttribute("problemLevelList", problemService.queryAllProblemLevel(parameters));
		request.setAttribute("addFlag", addFlag);
		return "admin/addProblem";
	}
	
	@RequestMapping("/problemList")
	public String problemList() {
		return "admin/problemList";
	}

	@RequestMapping("/problemType")
	public String prolemType() {
		return "admin/problemTypeList";
	}
}
